/*
    This is a set of libraries to assist in OpenGl and Other Applications
    Copyright (C) 2008  The Modular Engine Team

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

/// \file ClientModule.h
/// \brief Contains classes and functions relating to the ClientModule

#ifndef CLIENTMODULE_H
#define CLIENTMODULE_H
#include "EngineCore.h"
#include "ConsoleModule.h"
#include "networkData.h"
#include <vector>

#undef CLASSDECL
#ifdef CLIENTMODULE
	#define CLASSDECL __declspec(dllexport)
	#pragma comment( lib, "WS2_32.lib" )
#else
	#pragma comment( lib, "ClientModule.lib" )
	#define CLASSDECL __declspec(dllimport)
#endif


namespace ModularEngine
{

	/// Connect to another computer
	CFUNCTOR( cCONNECT, "connect", std::string mIpAddress; int mPort; );
	//CFUNCTOR( cSEND, "send" );

	/// The module to allow a client to interface with a server as defined by this program.

	/// TODO
	class CLASSDECL ClientModule: BASE( ClientModule )
	{
	protected:
		struct addrinfo *result, *ptr, hints;
		WSADATA wsaData;
		int iResult;
		int nCurrMessageNumber;
	public:
		SOCKET ConnectSocket;
		HANDLE mClientDataMutex;

		ClientModule()
		{
			processMessage = 0;
		}

		std::string ipAddress;

		bool mbConnected;

		std::vector<NetworkMessage> mMessages;

		//std::list<simpleMessage> mMessages;

		void sendMessage( NetworkMessage nMsg );
		void sendMessage( int nMessage, const char *pBuffer = 0, int nSize = 0 );

		NetworkMessageProcFunctor *processMessage;

		int initClient();
		int initialize();
		int run();

	};

}

#endif